# SPDX-License-Identifier: GPL-2.0
%YAML 1.2
---
$id: http://devicetree.org/schemas/net/snps,dwmac.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#

title: Synopsys DesignWare MAC

maintainers:
  - Alexandre Torgue <alexandre.torgue@foss.st.com>
  - Giuseppe Cavallaro <peppe.cavallaro@st.com>
  - Jose Abreu <joabreu@synopsys.com>

# Select every compatible, including the deprecated ones. This way, we
# will be able to report a warning when we have that compatible, since
# we will validate the node thanks to the select, but won't report it
# as a valid value in the compatible property description
select:
  properties:
    compatible:
      contains:
        enum:
          - snps,dwmac
          - snps,dwmac-3.40a
          - snps,dwmac-3.50a
          - snps,dwmac-3.610
          - snps,dwmac-3.70a
          - snps,dwmac-3.710
          - snps,dwmac-4.00
          - snps,dwmac-4.10a
          - snps,dwmac-4.20a
          - snps,dwmac-5.10a
          - snps,dwxgmac
          - snps,dwxgmac-2.10

          # Deprecated
          - st,spear600-gmac

  required:
    - compatible

properties:

  # We need to include all the compatibles from schemas that will
  # include that schemas, otherwise compatible won't validate for
  # those.
  compatible:
    contains:
      enum:
        - allwinner,sun7i-a20-gmac
        - allwinner,sun8i-a83t-emac
        - allwinner,sun8i-h3-emac
        - allwinner,sun8i-r40-gmac
        - allwinner,sun8i-v3s-emac
        - allwinner,sun50i-a64-emac
        - amlogic,meson6-dwmac
        - amlogic,meson8b-dwmac
        - amlogic,meson8m2-dwmac
        - amlogic,meson-gxbb-dwmac
        - amlogic,meson-axg-dwmac
        - ingenic,jz4775-mac
        - ingenic,x1000-mac
        - ingenic,x1600-mac
        - ingenic,x1830-mac
        - ingenic,x2000-mac
        - loongson,ls2k-dwmac
        - loongson,ls7a-dwmac
        - renesas,r9a06g032-gmac
        - renesas,rzn1-gmac
        - rockchip,px30-gmac
        - rockchip,rk3128-gmac
        - rockchip,rk3228-gmac
        - rockchip,rk3288-gmac
        - rockchip,rk3328-gmac
        - rockchip,rk3366-gmac
        - rockchip,rk3368-gmac
        - rockchip,rk3588-gmac
        - rockchip,rk3399-gmac
        - rockchip,rv1108-gmac
        - snps,dwmac
        - snps,dwmac-3.40a
        - snps,dwmac-3.50a
        - snps,dwmac-3.610
        - snps,dwmac-3.70a
        - snps,dwmac-3.710
        - snps,dwmac-4.00
        - snps,dwmac-4.10a
        - snps,dwmac-4.20a
        - snps,dwmac-5.10a
        - snps,dwxgmac
        - snps,dwxgmac-2.10

  reg:
    minItems: 1
    maxItems: 2

  interrupts:
    minItems: 1
    items:
      - description: Combined signal for various interrupt events
      - description: The interrupt to manage the remote wake-up packet detection
      - description: The interrupt that occurs when Rx exits the LPI state

  interrupt-names:
    minItems: 1
    items:
      - const: macirq
      - const: eth_wake_irq
      - const: eth_lpi

  clocks:
    minItems: 1
    maxItems: 8
    additionalItems: true
    items:
      - description: GMAC main clock
      - description: Peripheral registers interface clock
      - description:
          PTP reference clock. This clock is used for programming the
          Timestamp Addend Register. If not passed then the system
          clock will be used and this is fine on some platforms.

  clock-names:
    minItems: 1
    maxItems: 8
    additionalItems: true
    contains:
      enum:
        - stmmaceth
        - pclk
        - ptp_ref

  resets:
    maxItems: 1
    description:
      MAC Reset signal.

  reset-names:
    const: stmmaceth

  power-domains:
    maxItems: 1

  mac-mode:
    $ref: ethernet-controller.yaml#/properties/phy-connection-type
    description:
      The property is identical to 'phy-mode', and assumes that there is mode
      converter in-between the MAC & PHY (e.g. GMII-to-RGMII). This converter
      can be passive (no SW requirement), and requires that the MAC operate
      in a different mode than the PHY in order to function.

  snps,axi-config:
    $ref: /schemas/types.yaml#/definitions/phandle
    description:
      AXI BUS Mode parameters. Phandle to a node that can contain the
      following properties
        * snps,lpi_en, enable Low Power Interface
        * snps,xit_frm, unlock on WoL
        * snps,wr_osr_lmt, max write outstanding req. limit
        * snps,rd_osr_lmt, max read outstanding req. limit
        * snps,kbbe, do not cross 1KiB boundary.
        * snps,blen, this is a vector of supported burst length.
        * snps,fb, fixed-burst
        * snps,mb, mixed-burst
        * snps,rb, rebuild INCRx Burst

  snps,mtl-rx-config:
    $ref: /schemas/types.yaml#/definitions/phandle
    description:
      Multiple RX Queues parameters. Phandle to a node that
      implements the 'rx-queues-config' object described in
      this binding.

  rx-queues-config:
    type: object
    properties:
      snps,rx-queues-to-use:
        $ref: /schemas/types.yaml#/definitions/uint32
        description: number of RX queues to be used in the driver
      snps,rx-sched-sp:
        type: boolean
        description: Strict priority
      snps,rx-sched-wsp:
        type: boolean
        description: Weighted Strict priority
    allOf:
      - if:
          required:
            - snps,rx-sched-sp
        then:
          properties:
            snps,rx-sched-wsp: false
      - if:
          required:
            - snps,rx-sched-wsp
        then:
          properties:
            snps,rx-sched-sp: false
    patternProperties:
      "^queue[0-9]$":
        description: Each subnode represents a queue.
        type: object
        properties:
          snps,dcb-algorithm:
            type: boolean
            description: Queue to be enabled as DCB
          snps,avb-algorithm:
            type: boolean
            description: Queue to be enabled as AVB
          snps,map-to-dma-channel:
            $ref: /schemas/types.yaml#/definitions/uint32
            description: DMA channel id to map
          snps,route-avcp:
            type: boolean
            description: AV Untagged Control packets
          snps,route-ptp:
            type: boolean
            description: PTP Packets
          snps,route-dcbcp:
            type: boolean
            description: DCB Control Packets
          snps,route-up:
            type: boolean
            description: Untagged Packets
          snps,route-multi-broad:
            type: boolean
            description: Multicast & Broadcast Packets
          snps,priority:
            $ref: /schemas/types.yaml#/definitions/uint32
            description: Bitmask of the tagged frames priorities assigned to the queue
        allOf:
          - if:
              required:
                - snps,dcb-algorithm
            then:
              properties:
                snps,avb-algorithm: false
          - if:
              required:
                - snps,avb-algorithm
            then:
              properties:
                snps,dcb-algorithm: false
          - if:
              required:
                - snps,route-avcp
            then:
              properties:
                snps,route-ptp: false
                snps,route-dcbcp: false
                snps,route-up: false
                snps,route-multi-broad: false
          - if:
              required:
                - snps,route-ptp
            then:
              properties:
                snps,route-avcp: false
                snps,route-dcbcp: false
                snps,route-up: false
                snps,route-multi-broad: false
          - if:
              required:
                - snps,route-dcbcp
            then:
              properties:
                snps,route-avcp: false
                snps,route-ptp: false
                snps,route-up: false
                snps,route-multi-broad: false
          - if:
              required:
                - snps,route-up
            then:
              properties:
                snps,route-avcp: false
                snps,route-ptp: false
                snps,route-dcbcp: false
                snps,route-multi-broad: false
          - if:
              required:
                - snps,route-multi-broad
            then:
              properties:
                snps,route-avcp: false
                snps,route-ptp: false
                snps,route-dcbcp: false
                snps,route-up: false
        additionalProperties: false
    additionalProperties: false

  snps,mtl-tx-config:
    $ref: /schemas/types.yaml#/definitions/phandle
    description:
      Multiple TX Queues parameters. Phandle to a node that
      implements the 'tx-queues-config' object described in
      this binding.

  tx-queues-config:
    type: object
    properties:
      snps,tx-queues-to-use:
        $ref: /schemas/types.yaml#/definitions/uint32
        description: number of TX queues to be used in the driver
      snps,tx-sched-wrr:
        type: boolean
        description: Weighted Round Robin
      snps,tx-sched-wfq:
        type: boolean
        description: Weighted Fair Queuing
      snps,tx-sched-dwrr:
        type: boolean
        description: Deficit Weighted Round Robin
      snps,tx-sched-sp:
        type: boolean
        description: Strict priority
    allOf:
      - if:
          required:
            - snps,tx-sched-wrr
        then:
          properties:
            snps,tx-sched-wfq: false
            snps,tx-sched-dwrr: false
            snps,tx-sched-sp: false
      - if:
          required:
            - snps,tx-sched-wfq
        then:
          properties:
            snps,tx-sched-wrr: false
            snps,tx-sched-dwrr: false
            snps,tx-sched-sp: false
      - if:
          required:
            - snps,tx-sched-dwrr
        then:
          properties:
            snps,tx-sched-wrr: false
            snps,tx-sched-wfq: false
            snps,tx-sched-sp: false
      - if:
          required:
            - snps,tx-sched-sp
        then:
          properties:
            snps,tx-sched-wrr: false
            snps,tx-sched-wfq: false
            snps,tx-sched-dwrr: false
    patternProperties:
      "^queue[0-9]$":
        description: Each subnode represents a queue.
        type: object
        properties:
          snps,weight:
            $ref: /schemas/types.yaml#/definitions/uint32
            description: TX queue weight (if using a DCB weight algorithm)
          snps,dcb-algorithm:
            type: boolean
            description: TX queue will be working in DCB
          snps,avb-algorithm:
            type: boolean
            description:
              TX queue will be working in AVB.
              Queue 0 is reserved for legacy traffic and so no AVB is
              available in this queue.
          snps,send_slope:
            $ref: /schemas/types.yaml#/definitions/uint32
            description: enable Low Power Interface
          snps,idle_slope:
            $ref: /schemas/types.yaml#/definitions/uint32
            description: unlock on WoL
          snps,high_credit:
            $ref: /schemas/types.yaml#/definitions/uint32
            description: max write outstanding req. limit
          snps,low_credit:
            $ref: /schemas/types.yaml#/definitions/uint32
            description: max read outstanding req. limit
          snps,priority:
            $ref: /schemas/types.yaml#/definitions/uint32
            description:
              Bitmask of the tagged frames priorities assigned to the queue.
              When a PFC frame is received with priorities matching the bitmask,
              the queue is blocked from transmitting for the pause time specified
              in the PFC frame.
        allOf:
          - if:
              required:
                - snps,dcb-algorithm
            then:
              properties:
                snps,avb-algorithm: false
          - if:
              required:
                - snps,avb-algorithm
            then:
              properties:
                snps,dcb-algorithm: false
                snps,weight: false
        additionalProperties: false
    additionalProperties: false

  snps,reset-gpio:
    deprecated: true
    maxItems: 1
    description:
      PHY Reset GPIO

  snps,reset-active-low:
    deprecated: true
    $ref: /schemas/types.yaml#/definitions/flag
    description:
      Indicates that the PHY Reset is active low

  snps,reset-delays-us:
    deprecated: true
    description:
      Triplet of delays. The 1st cell is reset pre-delay in micro
      seconds. The 2nd cell is reset pulse in micro seconds. The 3rd
      cell is reset post-delay in micro seconds.
    minItems: 3
    maxItems: 3

  snps,aal:
    $ref: /schemas/types.yaml#/definitions/flag
    description:
      Use Address-Aligned Beats

  snps,fixed-burst:
    $ref: /schemas/types.yaml#/definitions/flag
    description:
      Program the DMA to use the fixed burst mode

  snps,mixed-burst:
    $ref: /schemas/types.yaml#/definitions/flag
    description:
      Program the DMA to use the mixed burst mode

  snps,force_thresh_dma_mode:
    $ref: /schemas/types.yaml#/definitions/flag
    description:
      Force DMA to use the threshold mode for both tx and rx

  snps,force_sf_dma_mode:
    $ref: /schemas/types.yaml#/definitions/flag
    description:
      Force DMA to use the Store and Forward mode for both tx and
      rx. This flag is ignored if force_thresh_dma_mode is set.

  snps,en-tx-lpi-clockgating:
    $ref: /schemas/types.yaml#/definitions/flag
    description:
      Enable gating of the MAC TX clock during TX low-power mode

  snps,multicast-filter-bins:
    $ref: /schemas/types.yaml#/definitions/uint32
    description:
      Number of multicast filter hash bins supported by this device
      instance

  snps,perfect-filter-entries:
    $ref: /schemas/types.yaml#/definitions/uint32
    description:
      Number of perfect filter entries supported by this device
      instance

  snps,ps-speed:
    $ref: /schemas/types.yaml#/definitions/uint32
    description:
      Port selection speed that can be passed to the core when PCS
      is supported. For example, this is used in case of SGMII and
      MAC2MAC connection.

  snps,clk-csr:
    $ref: /schemas/types.yaml#/definitions/uint32
    description:
      Frequency division factor for MDC clock.

  mdio:
    $ref: mdio.yaml#
    unevaluatedProperties: false
    description:
      Creates and registers an MDIO bus.

    properties:
      compatible:
        const: snps,dwmac-mdio

    required:
      - compatible

  stmmac-axi-config:
    type: object
    unevaluatedProperties: false
    description:
      AXI BUS Mode parameters.

    properties:
      snps,lpi_en:
        $ref: /schemas/types.yaml#/definitions/flag
        description:
          enable Low Power Interface

      snps,xit_frm:
        $ref: /schemas/types.yaml#/definitions/flag
        description:
          unlock on WoL

      snps,wr_osr_lmt:
        $ref: /schemas/types.yaml#/definitions/uint32
        description:
          max write outstanding req. limit

      snps,rd_osr_lmt:
        $ref: /schemas/types.yaml#/definitions/uint32
        description:
          max read outstanding req. limit

      snps,kbbe:
        $ref: /schemas/types.yaml#/definitions/uint32
        description:
          do not cross 1KiB boundary.

      snps,blen:
        $ref: /schemas/types.yaml#/definitions/uint32-array
        description:
          this is a vector of supported burst length.
        minItems: 7
        maxItems: 7

      snps,fb:
        $ref: /schemas/types.yaml#/definitions/flag
        description:
          fixed-burst

      snps,mb:
        $ref: /schemas/types.yaml#/definitions/flag
        description:
          mixed-burst

      snps,rb:
        $ref: /schemas/types.yaml#/definitions/flag
        description:
          rebuild INCRx Burst

required:
  - compatible
  - reg
  - interrupts
  - interrupt-names
  - phy-mode

dependencies:
  snps,reset-active-low: ["snps,reset-gpio"]
  snps,reset-delays-us: ["snps,reset-gpio"]

allOf:
  - $ref: "ethernet-controller.yaml#"
  - if:
      properties:
        compatible:
          contains:
            enum:
              - allwinner,sun7i-a20-gmac
              - allwinner,sun8i-a83t-emac
              - allwinner,sun8i-h3-emac
              - allwinner,sun8i-r40-gmac
              - allwinner,sun8i-v3s-emac
              - allwinner,sun50i-a64-emac
              - ingenic,jz4775-mac
              - ingenic,x1000-mac
              - ingenic,x1600-mac
              - ingenic,x1830-mac
              - ingenic,x2000-mac
              - snps,dwmac-3.50a
              - snps,dwmac-4.10a
              - snps,dwmac-4.20a
              - snps,dwxgmac
              - snps,dwxgmac-2.10
              - st,spear600-gmac

    then:
      properties:
        snps,pbl:
          description:
            Programmable Burst Length (tx and rx)
          $ref: /schemas/types.yaml#/definitions/uint32
          enum: [1, 2, 4, 8, 16, 32]

        snps,txpbl:
          description:
            Tx Programmable Burst Length. If set, DMA tx will use this
            value rather than snps,pbl.
          $ref: /schemas/types.yaml#/definitions/uint32
          enum: [1, 2, 4, 8, 16, 32]

        snps,rxpbl:
          description:
            Rx Programmable Burst Length. If set, DMA rx will use this
            value rather than snps,pbl.
          $ref: /schemas/types.yaml#/definitions/uint32
          enum: [1, 2, 4, 8, 16, 32]

        snps,no-pbl-x8:
          $ref: /schemas/types.yaml#/definitions/flag
          description:
            Don\'t multiply the pbl/txpbl/rxpbl values by 8. For core
            rev < 3.50, don\'t multiply the values by 4.

  - if:
      properties:
        compatible:
          contains:
            enum:
              - allwinner,sun7i-a20-gmac
              - allwinner,sun8i-a83t-emac
              - allwinner,sun8i-h3-emac
              - allwinner,sun8i-r40-gmac
              - allwinner,sun8i-v3s-emac
              - allwinner,sun50i-a64-emac
              - loongson,ls2k-dwmac
              - loongson,ls7a-dwmac
              - ingenic,jz4775-mac
              - ingenic,x1000-mac
              - ingenic,x1600-mac
              - ingenic,x1830-mac
              - ingenic,x2000-mac
              - snps,dwmac-4.00
              - snps,dwmac-4.10a
              - snps,dwmac-4.20a
              - snps,dwmac-5.10a
              - snps,dwxgmac
              - snps,dwxgmac-2.10
              - st,spear600-gmac

    then:
      properties:
        snps,tso:
          $ref: /schemas/types.yaml#/definitions/flag
          description:
            Enables the TSO feature otherwise it will be managed by
            MAC HW capability register.

additionalProperties: true

examples:
  - |
    gmac0: ethernet@e0800000 {
        compatible = "snps,dwxgmac-2.10", "snps,dwxgmac";
        reg = <0xe0800000 0x8000>;
        interrupt-parent = <&vic1>;
        interrupts = <24 23 22>;
        interrupt-names = "macirq", "eth_wake_irq", "eth_lpi";
        mac-address = [000000000000]; /* Filled in by U-Boot */
        max-frame-size = <3800>;
        phy-mode = "gmii";
        snps,multicast-filter-bins = <256>;
        snps,perfect-filter-entries = <128>;
        rx-fifo-depth = <16384>;
        tx-fifo-depth = <16384>;
        clocks = <&clock>;
        clock-names = "stmmaceth";
        snps,axi-config = <&stmmac_axi_setup>;
        snps,mtl-rx-config = <&mtl_rx_setup>;
        snps,mtl-tx-config = <&mtl_tx_setup>;

        stmmac_axi_setup: stmmac-axi-config {
            snps,wr_osr_lmt = <0xf>;
            snps,rd_osr_lmt = <0xf>;
            snps,blen = <256 128 64 32 0 0 0>;
        };

        mtl_rx_setup: rx-queues-config {
            snps,rx-queues-to-use = <1>;
            snps,rx-sched-sp;
            queue0 {
                snps,dcb-algorithm;
                snps,map-to-dma-channel = <0x0>;
                snps,priority = <0x0>;
            };
        };

        mtl_tx_setup: tx-queues-config {
            snps,tx-queues-to-use = <2>;
            snps,tx-sched-wrr;
            queue0 {
                snps,weight = <0x10>;
                snps,dcb-algorithm;
                snps,priority = <0x0>;
            };

            queue1 {
                snps,avb-algorithm;
                snps,send_slope = <0x1000>;
                snps,idle_slope = <0x1000>;
                snps,high_credit = <0x3E800>;
                snps,low_credit = <0xFFC18000>;
                snps,priority = <0x1>;
            };
        };

        mdio0 {
            #address-cells = <1>;
            #size-cells = <0>;
            compatible = "snps,dwmac-mdio";
            phy1: ethernet-phy@0 {
                reg = <0>;
            };
        };
    };

# FIXME: We should set it, but it would report all the generic
# properties as additional properties.
# additionalProperties: false

...
